<%--
  Created by IntelliJ IDEA.
  User: sunyb
  Date: 2017/8/3
  Time: 13:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/base.jsp" %>
<html>
<head>
    <link href="${ctx}/jquery-easyui-1.5.1/themes/default/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon-standard.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/jquery-easyui-1.5.1/themes/icon-hamburg.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/css/head.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/css/index.css" rel="stylesheet" type="text/css">
    <script src="${ctx}/js/jquery.min.js"></script>
    <script src="${ctx}/js/HdUtil.js"></script>
    <script src="${ctx}/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
    <script src="${ctx}/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">

        function countrySearch(newValue) {

        }

        function countrys(newValue) {

        }


        function query() {
            $("#sysCodeTable").datagrid("load", {
                fldEng: $("#companyName").textbox("getValue"),
                code: $("#companyNature").textbox("getValue")
            });
        }

        function add() {
            $("#sysCodeForm").form("clear");
            $("#sysCodeDialog").dialog("open");
        }

        function edit() {
            var rowdata = $("#sysCodeTable").datagrid("getSelected");
            var rowdata1 = $("#sysCodeTable").datagrid("getChecked");
            if (rowdata1.length != '1') {

                HdUtil.messager.info(HdUtil.constant.SELECT_EDIT_ROW);
            } else {
                //alert(rowdata1.length);
                //console.log(rowdata1);
                //alert(rowdata.size);
                if (rowdata) {
                    $("#sysCodeForm").form("clear");
                    $("#sysCodeForm").form("load", rowdata);
                    $("#sysCodeDialog").dialog("open");
                } else {
                    HdUtil.messager.info(HdUtil.constant.SELECT_EDIT_ROW);
                }
            }

        }

        function deleteRow() {
            var rowdata = $("#sysCodeTable").datagrid("getSelected");
            var rowdata1 = $("#sysCodeTable").datagrid("getChecked");
            //console.log(rowdata);
            if (rowdata1) {


                $.messager.confirm(HdUtil.constant.CONFIRM, HdUtil.constant.DELETE_CONFIRM, function (r) {
                    if (r) {
                        var j=0;
                        var k=rowdata1.length-1;
                        for (var i = 0; i < rowdata1.length; i++) {
                            //alert(i);
                            //console.log(rowdata1[i]);
                            var obj = rowdata1[i];
                            $.ajax({
                                url: "${ctx}/Company/delete?id=" + obj.companyId,
                                type: "post",
                                success: function (data) {
                                    //alert(data);
                                    if ("ok" == data) {
                                        j=j+1;

                                    }
                                }
                            })
                            //alert("j:"+j);
                            //alert("k:"+k);
                            //console.log(j);
                            //console.log(k);
                            //if(j==k){


                            //}
                        }
                        HdUtil.messager.slide(HdUtil.constant.DELETE_SUCCESS);
                        $("#sysCodeTable").datagrid("reload");


                    }
                });


            } else {
                HdUtil.messager.info(HdUtil.constant.SELECT_DELETE_ROW);
            }
        }

        $(document).ready(function () {

            $("#companyNature").combobox({
                url: "${ctx}/Company/getSysCodeList?q=COMP_AA",
                valueField: "code",
                textField: "name"
            });


            $("#companyNature2").combobox({
                url: "${ctx}/Company/getSysCodeList?q=COMP_AA",
                valueField: "code",
                textField: "name"
            });


            /*
             $('#cc').calendar({
             current:new Date()
             });

             $('#phone').calendar({
             onSelect: function(date){
             alert(date.getFullYear()+":"+(date.getMonth()+1)+":"+date.getDate());
             }
             });


             $('#phone').combobox({
             onChange:function(){
             alert("onChange");
             }
             onSelect:function(){
             alert("onSelect");
             }
             });*/

            function fun() {
                $("#datedlg").dialog('open');
                $('#cc').calendar({
                    onSelect: function (date) {
                        var myyear = date.getFullYear();
                        var mymonth = ((date.getMonth() + 1) < 10 ? ('0' + (date.getMonth() + 1)) : (date.getMonth() + 1));
                        var mydate = ((date.getDate()) < 10 ? ('0' + (date.getDate())) : (date.getDate()));
                        var thesedays = myyear + "-" + mymonth + "-" + mydate;
                        //$(e.data.target).textbox('setText',thesedays);
                        $('#phone').textbox('setText', thesedays);
                        $("#datedlg").dialog('close');
                    }
                });
            };
            /*
             $('#phone').textbox({
             onChange: function(value) {
             alert($("#phone").textbox("getValue"));
             }
             });*/
            /*
             $('#phone').textbox('textbox').bind('click', function () {
             fun()
             });
             */

            /*

             $('#linkMan').combogrid({
             panelWidth:500,
             url: 'form5_getdata.php',
             idField:'itemid',
             textField:'productid',
             mode:'remote',
             fitColumns:true,
             columns:[[
             {field:'itemid',title:'Item ID',width:60},
             {field:'productid',title:'Product ID',align:'right',width:80},
             {field:'listprice',title:'List Price',align:'right',width:60},
             {field:'unitcost',title:'Unit Cost',align:'right',width:60},
             {field:'attr1',title:'Attribute',width:150},
             {field:'status',title:'Stauts',align:'center',width:60}
             ]]
             });
             */

            $('#linkMan').combogrid({
                panelWidth: 500,
                //method:'get',
                data: {
                    'total': 1, 'rows': [
                        {itemid:'1',productid: '1', listprice: '2', unitcost: '3', attr1: '2', status: '1'},
                        {itemid:'2',productid: '12', listprice: '12', unitcost: '13', attr1: '12', status: '11'},
                        {itemid:'3',productid: '22', listprice: '22', unitcost: '23', attr1: '22', status: '21'}
                    ]
                },
                idField: 'itemid',
                textField: 'productid',
                mode: 'remote',
                fitColumns: true,
                columns: [[
                    {field: 'productid', title: '姓名', align: 'center', width: 60},
                    {field: 'listprice', title: '职务', align: 'center', width: 60},
                    {field: 'unitcost', title: '科室', align: 'center', width: 60},
                    {field: 'attr1', title: '电话', align: 'center', width: 60},
                    {field: 'status', title: '办公地点', align: 'center', width: 60}
                ]],
                /*
                 onDblClickCell: function(index,field,value){
                 $(this).datagrid('beginEdit', index);
                 var ed = $(this).datagrid('getEditor', {index:index,field:field});
                 $(ed.target).focus();
                 }
                 */
                onClickRow: function (rowIndex, rowData) {
                    //console.log(rowData);
                    //alert(rowData.productid);
                    $('#linkMan').textbox('setText', rowData.productid);
                    //$(this).datagrid('beginEdit', rowIndex);
                    //var ed = $(this).datagrid('getEditor', {index:index,field:field});
                    //var ed = $(this).datagrid('getEditor', {index:index,field:field});
                    //$(ed.target).focus();
                }
            });


// 下拉框选择控件，下拉框的内容是动态查询数据库信息
            $('#province').combobox({
                url: 'apply/provinceCombobox_combobox.action',
                editable: true, //不可编辑状态
                cache: false,
                // panelHeight: 'auto',//自动高度适合
                valueField: 'code',
                textField: 'note',
                onHidePanel: function () {
                    //$("#province").combobox("setValue",'');
                    //$("#city").combobox("setValue",'');
                    //$("#distric").val('');
                    var province = $('#province').combobox('getValue');
                    if (province != '') {
                        $.ajax({
                            type: "POST",
                            url: "apply/cityCombobox_combobox.action?province=" + province,
                            cache: false,
                            dataType: "json",
                            success: function (data) {
                                $("#city").combobox("loadData", data);
                            }
                        });
                    }
                }
            });

            $('#city').combobox({

                editable: false, //不可编辑状态
                cache: false,
                //panelHeight: 'auto',//自动高度适合
                valueField: 'code',
                textField: 'note',
                onHidePanel: function () {
                    //$("#distric").val('');
                    //$("#province").combobox("setValue",'');
                    var city = $('#city').combobox('getValue');
                    if (city != '') {
                        $.ajax({
                            type: "POST",
                            url: "apply/countyCombobox_combobox.action?city=" + city,
                            cache: false,
                            dataType: "json",
                            success: function (data) {
                                $("#province").combobox("loadData", data);
                            }
                        });
                    }
                }
            });
            $('#city').combobox({
                editable: true, //不可编辑状态
                cache: false,
                // panelHeight: 'auto',//自动高度适合
                valueField: 'code',
                textField: 'note',
                onHidePanel: function () {
                    var str = $('#city').combobox('getText');
                    $("#distrc").val(str);
                }
            });

            $('#province').combobox({//省级代码初始化
                valueField: 'english',
                textField: 'note',
                url: 'json/province.json',
                cache: false,
                //panelHeight: 'auto',//自动高度适合
                onChange: function (newValue, oldValue) {

                    countrySearch(newValue);
                    countrys(newValue);
                }
            });

            var dataGridObj = $("#sysCodeTable");
            dataGridObj.datagrid({
                url: "${ctx}/Company/getSysCodeData",
                method: "get",
                striped: true,
                pagination: true,
                singleSelect: false,
                checkOnSelect: true,
                selectOnCheck: true,
                rownumbers: true,
                pageSize: 50,
                toolbar: "#sysCodeTableToolbar",
                fit: true,
                sortName: "companyName",
                sortOrder: "asc",
                fitColumns: false,
                columns: [[


                    {
                        field: "companyId",

                        checkbox:true
                    },

                    {
                        field: "companyName",
                        title: "公司名称",
                        multiSort: true,
                        width: 140,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "companyNature",
                        title: "公司性质",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "companyAddress",
                        title: "公司地址",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "phone",
                        title: "日期",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "linkMan",
                        title: "联系人",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "province",
                        title: "省",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "city",
                        title: "市",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    },
                    {
                        field: "distric",
                        title: "区",
                        multiSort: true,
                        width: 120,
                        sortable: true,
                        halign: "center"
                    }
                ]]
            });
            $("#sysCodeDialog").dialog({
                title: "公司表维护",
                width: 550,
                height: 340,
                closed: true,
                cache: false,
                modal: true,
                buttons: [{
                    text: '保存',
                    handler: function () {
                        if ($("#sysCodeForm").form("validate")) {
                            $.messager.progress();
                            $("#sysCodeForm").submit();
                        }
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $("#sysCodeDialog").dialog("close");
                    }
                }]
            });
            /*
             if($("#sysCodeForm").form('validate')){

             }else{
             $.messager.alert('操作提示','存在校验项未通过！',"warning");
             }
             */

            $('#sysCodeForm').form({
                url: "${ctx}/Company/save",
                success: function (data) {
                    $.messager.progress('close');
                    if ("ok" == data) {
                        $("#sysCodeDialog").dialog("close");
                        HdUtil.messager.slide(HdUtil.constant.SAVE_SUCCESS);
                        $("#sysCodeTable").datagrid("reload");
                    } else {
                        HdUtil.messager.error(data);
                    }
                }
            });
            $("#sysCodeTableToolbar a[iconCls='icon-more']").on("click", function () {
                $.hdd.ezui.doCommonQuery(dataGridObj, $("#sysCodeQueryDialog"), function (param) {
                    dataGridObj.datagrid("load", param);
                });
            });


        });
    </script>
</head>
<body>
<div id="sysCodeTableToolbar">
    公司名称：<input id="companyName" class="easyui-textbox"> 公司性质：<input id="companyNature" class="easyui-combobox">
    <shiro:hasPermission name="sysCode:query">
        <a class="easyui-linkbutton" iconCls="icon-search" plain="false" onclick="query()">查询</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="sysCode:add">
        <a class="easyui-linkbutton" iconCls="icon-add" plain="false" onclick="add()">新增</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="sysCode:edit">
        <a class="easyui-linkbutton" iconCls="icon-edit" plain="false" onclick="edit()">编辑</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="sysCode:delete">
        <a class="easyui-linkbutton" iconCls="icon-remove" plain="false" onclick="deleteRow()">删除</a>
    </shiro:hasPermission>
</div>
<table id="sysCodeTable"></table>
<div id="sysCodeDialog">
    <form id="sysCodeForm" method="post">
        <table align="center" style="height:60%;weight:100%">
            <tr>
                <td>名称：</td>
                <td>
                    <input name="companyName" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'名称\',100]']">
                </td>

                <td>性质：</td>
                <td>
                    <input name="companyNature" class="easyui-combox" id="companyNature2"
                           data-options="required:true,validType:['maxLength[\'性质\',100]']">
                </td>
            </tr>
            <tr>
                <td>地址：</td>
                <td>
                    <input name="companyAddress" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'地址\',100]']">
                </td>

                <td>日期：</td>
                <td>
                    <input name="phone" class="easyui-datebox" id="phone1"
                           data-options="required:true,validType:['maxLength[\'日期\',100]']">
                </td>
            </tr>

            <tr>
                <td>联系人：</td>
                <td>
                    <input name="linkMan" id="linkMan" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'联系人\',100]']">
                </td>

                <td>省：</td>
                <td>
                    <input name="province" id="province" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'省\',100]']">
                </td>
            </tr>
            <tr>
                <td>市：</td>
                <td>
                    <input name="city" id="city" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'市\',100]']">
                </td>

                <td>区：</td>
                <td>
                    <input name="distric" id="distric" class="easyui-textbox"
                           data-options="required:true,validType:['maxLength[\'区\',100]']">
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <input name="companyId" type="hidden" value="1">
                    <input name="uniformSocialCreditCode" type="hidden" value="1">
                    <input name="businessLicenseImgUrl" type="hidden" value="1">
                    <input name="role" type="hidden" value="1">
                    <input name="cargoPactFlag" type="hidden" value="1">
                    <input name="cargoFowarderFlag" type="hidden" value="1">
                    <input name="isCheck" type="hidden" value="1">
                    <input name="cntrTruckOrderFlag" type="hidden" value="1">
                    <input name="orderLimitFlag" type="hidden" value="1">
                    <input name="gctosUnitCod" type="hidden" value="1">
                    <input name="gctosShipperCod" type="hidden" value="1">
                    <input name="shipAgentFlag" type="hidden" value="1">
                    <input name="cargoAgentFlag" type="hidden" value="1">
                    <input name="truckTeamFlag" type="hidden" value="1">
                    <input name="shipCorpFlag" type="hidden" value="1">
                    <input name="cntrCorpFlag" type="hidden" value="1">
                    <input name="cntrOperFlag" type="hidden" value="1">
                    <input name="shipOwnerFlag" type="hidden" value="1">
                    <input name="cargoOwnerFlag" type="hidden" value="1">
                    <input name="cargoWorkCompanyFlag" type="hidden" value="1">
                    <input name="shipFeeUnitFalg" type="hidden" value="1">
                    <input name="companyCode" type="hidden" value="1">
                    <input name="companyNameEn" type="hidden" value="1">
                    <input name="gjCorpCod" type="hidden" value="1">
                    <input name="dlCorpCod" type="hidden" value="1">
                    <input name="companyEaddress" type="hidden" value="1">
                    <input name="shortName" type="hidden" value="1">
                </td>
            </tr>
        </table>


    </form>
</div>
<!--
<div id="datedlg" class="easyui-dialog" title="请点击选择日期" data-options="iconCls:'icon-save',closed:true" style="width:400px;
height:300px;padding:10px">
    <div class="easyui-calendar" id="cc" style="width:100%;height:250px;">
    </div>
</div>
-->
<div id="sysCodeQueryDialog"/>
</body>
</html>